package ca.venasse.pinventory.part.command;

import org.axonframework.commandhandling.annotation.CommandHandler;
import org.axonframework.repository.Repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ca.venasse.pinventory.part.domain.Part;

@Component
public class PartCommandHandler {

	@Autowired
	private Repository<Part> repository;

	@CommandHandler
	public void createPart(CreatePartCommand command) {
		Part part = new Part(
			command.getAggregateIdentifier(),
			command.getName(),
			command.getCategory());
		this.repository.add(part);
	}

	public void setRepository(Repository<Part> repository) {
		this.repository = repository;
	}

}
